﻿using AbpEntityFrameworkcore.DbContext;
using AbpToDomain.EntityInfo;
using AbpToDomain.View;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AbpApplication.Expand
{
    public class QueryDynamic_View_Materials
    {

        private readonly MyDbContext context;

        public QueryDynamic_View_Materials(MyDbContext context)
        {
            this.context = context;
        }

        public List<View_Materials> QueryDynameic(string? MaterialName,string?MaterialCode,
            
            string? Batch,int? Quantity, string? BoxGridCode)
        {
            IQueryable<View_Materials> view_Materials = context.viewMaterials.OrderByDescending(x=>x.CreatedDate);
            if (!string.IsNullOrEmpty(BoxGridCode))
            {
                view_Materials = view_Materials.Where(b => b.BoxGridCode.Contains(BoxGridCode));
            }
            if (!string.IsNullOrEmpty(MaterialName))
            {
                view_Materials = view_Materials.Where(b => b.MaterialName.Contains(MaterialName));
            }
            if (!string.IsNullOrEmpty(MaterialCode))
            {
                view_Materials = view_Materials.Where(b => b.MaterialCode.Contains(MaterialCode));
            }
            if (!string.IsNullOrEmpty(Batch))
            {
                view_Materials = view_Materials.Where(b => b.Batch.Contains(Batch));
            }
            if (!string.IsNullOrEmpty(Quantity.ToString()))
            {
                view_Materials = view_Materials.Where(b => b.Quantity==Quantity);
            }
            return view_Materials.ToList();
        }
    }
}
